import {
  Controller,
  Post,
  HttpCode,
  HttpStatus,
  Body,
  Get,
  Query,
} from '@nestjs/common';
import { UserService } from './user.service';
import { DetailsParam, UpdateDetailsParam } from './user.interface';
import { UserRegisterDTO } from './dto/user-register.dto';
import { ApiTags, ApiOperation } from '@nestjs/swagger';

@ApiTags('后台用户管理模块')
@Controller('user')
export class UserController {
  constructor(private readonly service: UserService) {}

  // 登陆
  @Post('login')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: '登陆' })
  login(@Body() dto: UserRegisterDTO) {
    return this.service.loginService(dto);
  }

  // 注册
  @Post('register')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: '注册' })
  register(@Body() userRegisterDTO: UserRegisterDTO) {
    return this.service.registerService(userRegisterDTO);
  }

  // 获取用户列表
  @Get('query')
  @ApiOperation({ summary: '获取用户列表' })
  queryUsers() {
    return this.service.queryUsersService();
  }

  // 获取用户详情信息
  @Get('detail')
  @ApiOperation({ summary: '获取用户详情信息' })
  getDetails(@Query() params: DetailsParam) {
    return this.service.queryDetailsService(params);
  }

  // 更新用户详情信息
  @Post('update')
  @ApiOperation({ summary: '更新用户详情信息' })
  @HttpCode(HttpStatus.OK)
  updateDetails(@Body() params: UpdateDetailsParam) {
    return this.service.updateDetailsService(params);
  }

  // 删除用户
  @Post('delete')
  @ApiOperation({ summary: '删除用户' })
  @HttpCode(HttpStatus.OK)
  deleteUser(@Body() params: { id: number }) {
    return this.service.deleteUserService(params);
  }

  // 注销用户
  @Post('logout')
  @ApiOperation({ summary: '注销用户' })
  @HttpCode(HttpStatus.OK)
  logout(@Body() params: { id: number }) {
    return this.service.logoutService(params);
  }
}
